import storage from "/src/components/node-kantboot/libs/storage"

/**
 * 获取所有工作系列
 */
let getWorkSeriesList = function() {
    return storage.get("workSeriesList");
}

/**
 * 根据id获取工作系列
 */
let getWorkSeriesById = function(id) {
    return storage.get("workSeriesMap")["workSeries_" + id];
}

/**
 * 获取技能等级计划列表
 */
let getSkillLevelList = function() {
    return storage.get("skillLevelList");
}


/**
 * 根据id获取技能等级计划
 */
let getSkillLevelById = function(id) {
    return storage.get("skillLevelMap")["skillLevel_" + id];
}




/**
 * 获取专家人才等级列表
 */
let getExpertLevelList = function() {
    return storage.get("expertLevelList");
}

/**
 * 根据id获取专家人才等级
 */
let getExpertLevelById = function(id) {
    return storage.get("expertLevelMap")["expertLevel_" + id];
}

/**
 * 获取人才计划列表
 */
let getTalentPlanList = function() {
    return storage.get("talentPlanList");
}

/**
 * 根据id获取人才计划
 */
let getTalentPlanById = function(id) {
    return storage.get("talentPlanMap")["talentPlan_" + id];
}

/**
 * 获取人才奖项的列表
 */
let getTalentAwardList = function() {
    return storage.get("talentAwardList");
}

/**
 * 根据id获取人才奖项
 */
let getTalentAwardById = function(id) {
    return storage.get("talentAwardMap")["talentAward_" + id];
}

/**
 * 获取所有学历列表
 */
let getEduLevelList = function() {
    return [
        {
            level: 1,
            name: "文盲"
        },
        {
            level: 2,
            name: "小学"
        },
        {
            level: 3,
            name: "初中"
        },
        {
            level: 4,
            name: "高中"
        },
        {
            level: 5,
            name: "大专"
        },
        {
            level: 6,
            name: "本科"
        },
        {
            level: 7,
            name: "硕士研究生"
        },
        {
            level: 8,
            name: "博士研究生"
        }
    ]
}

/**
 * 根据等级获取学历
 */
let getEduLevelByLevelNumber = function(levelNumber) {
    let eduMap = {
        1: "文盲",
        2: "小学",
        3: "初中",
        4: "高中",
        5: "大专",
        6: "本科",
        7: "硕士研究生",
        8: "博士研究生",
    };

    if(!eduMap[levelNumber]){
        return null
    }

    return {
        level: levelNumber,
        name: eduMap[levelNumber]
    };
}

/**
 * 根据编码获取专业
 */
let getEduMajorByCode = function(code) {
    return storage.get("eduMajorMap")["eduMajor_" + code];
}

/**
 * 获取职称列表
 */
let getTitleLevelList = function() {
    return storage.get("titleLevelList");
}

/**
 * 根据系列id获取职称列表
 */
let getTitleLevelListBySeriesId = function(seriesId) {
    // 从 storage 中获取 titleLevelList
    const titleLevelList = storage.get("titleLevelList") || [];

    // 过滤出匹配的项
    return titleLevelList.filter(item => item.seriesId == seriesId);
}

/**
 * 根据id获取职称
 */
let getTitleLevelById = function(id) {
    return storage.get("titleLevelMap")["titleLevel_" + id];
}

/**
 * 获取所有学科专业含子学科
 */
let getEduMajorListHasChildren = function() {
    return storage.get("eduMajorListHasChildren");
}

/**
 * 根据二级code获取门类
 */
let getEduMajorByLv2Code = function(code) {
    return storage.get("eduMajorL2Map")["eduMajorL2_" + code];
}

/**
 * getTalentAwardGradeList 获取奖项等级列表
 */
let getTalentAwardGradeList = function() {
    return [
        {
            value: 0,
            name: "特等奖"
        },
        {
            value: 1,
            name: "一等奖"
        },
        {
            value: 2,
            name: "二等奖"
        },
        {
            value: 3,
            name: "三等奖"
        },
        {
            value: 4,
            name: "四等奖"
        },
        {
            value: 5,
            name: "五等奖"
        }
    ]
}

/**
 * getTalentAwardRankList 获取奖项等次列表
 */
let getTalentAwardRankList = function() {
    let result = [];
    // 返回 1-100 名 value 为数字 name 为中文用方法
    for (let i = 1; i<=100; i++) {
        result.push({
            value: i,
            name: "第" + i + "名"
        })
    }
    return result;
}

/**
 * getTalentPerformanceYearList 获取年度列表当前时间前5年 例如 2012年前5年 2017,2018,2019,2020,2021
 */
let getTalentPerformanceYearList = function() {
    let result = [];
    let currentYear = new Date().getFullYear();
    for (let i = 1; i<=5; i++) {
        result.push({
            value: currentYear - i,
            name: currentYear - i + "年"
        });
    }
    return result;
}

export default {
    getWorkSeriesList,
    getWorkSeriesById,
    getSkillLevelList,
    getSkillLevelById,
    getExpertLevelList,
    getExpertLevelById,
    getTalentPlanList,
    getTalentPlanById,
    getTalentAwardList,
    getTalentAwardById,
    getEduLevelList,
    getEduLevelByLevelNumber,
    getEduMajorByCode,
    getTitleLevelList,
    getTitleLevelById,
    getTitleLevelListBySeriesId,
    getEduMajorListHasChildren,
    getEduMajorByLv2Code,
    getTalentAwardGradeList,
    getTalentAwardRankList,
    getTalentPerformanceYearList
}